In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
from scipy.optimize import newton
import scipy.constants as sc
import numpy as np
import matplotlib.pyplot as plt
In [2]:
from pypvcell.solarcell import SQCell, MJCell,ResistorCell,SolarCell,SeriesConnect,ParallelConnect,DiodeSeriesConnect
from pypvcell.illumination import load_astm
In [3]:
r1cell=ResistorCell(1.0)
r2cell=ResistorCell(2.0)
In [4]:
sc_comp=SeriesConnect([r1cell, r2cell])
In [5]:
test_c=np.linspace(0,2,10)
test_v=sc_comp.get_v_from_j(test_c)
plt.plot(test_v,test_c)
test_v[5]/test_c[5]
Out[5]:
In [6]:
test_v=3
test_c=sc_comp.get_single_j_from_v(test_v)
test_c
Out[6]:
In [7]:
test_v=np.linspace(0,6,10)
test_c=sc_comp.get_j_from_v(test_v)
plt.plot(test_v,test_c)
test_v[5]/test_c[5]
Out[7]:
In [8]:
r1cell.get_j_from_v_by_newton(2.5)
Out[8]:
In [9]:
pp_comp=ParallelConnect([r1cell, r2cell])
In [10]:
test_c=np.linspace(0,2,10)
test_v=pp_comp.get_v_from_j(test_c)
plt.plot(test_v,test_c)
test_v[5]/test_c[5]
Out[10]:
In [11]:
d1=SQCell(1.42,300)
d2=SQCell(1.42,300)
In [12]:
sd=SeriesConnect([d1,d2])
In [13]:
sd.get_single_j_from_v(1.6,0.002)
Out[13]:
In [14]:
d1.get_j_from_v(0.8)
Out[14]:
In [15]:
from pypvcell.illumination import load_astm
In [77]:
d1=SQCell(1.42,300)
d2=SQCell(1.42,300)
d1.set_input_spectrum(1.0*load_astm())
d2.set_input_spectrum(1.1*load_astm())
In [78]:
test_v=np.linspace(-1,1.1,30)
plt.plot(test_v,d1.get_j_from_v(test_v))
plt.plot(test_v,d2.get_j_from_v(test_v))
Out[78]:
In [79]:
test_v=np.linspace(-1,1.1,30)
plt.semilogy(test_v,np.abs(d1.get_j_from_v(test_v)))
plt.semilogy(test_v,np.abs(d2.get_j_from_v(test_v)))
Out[79]:
In [80]:
d1.get_j_from_v(test_v)
Out[80]:
In [81]:
sd=DiodeSeriesConnect([d1,d2])
In [85]:
d3=SQCell(1.42,cell_T=300)
In [91]:
d3.set_input_spectrum(load_astm())
print(test_v)
d3.get_j_from_v(test_v)
Out[91]:
In [92]:
d3.jsc
Out[92]:
In [43]:
sd.get_single_j_from_v(3.0,10)
Out[43]:
In [44]:
d1.get_j_from_v(1.5)
Out[44]:
In [45]:
sd.get_single_j_from_v(1.0,-310)
In [46]:
lower_bound_j=d1.get_j_from_v(-10)
print(lower_bound_j)
sd.get_single_j_from_v_bisect(1.0,lower_bound_j,0)
In [47]:
test_v=np.linspace(-320.42,0,30)
plt.plot(test_v,d1.get_v_from_j(test_v))
Out[47]:
In [48]:
test_v=np.linspace(0,2.5,30)
plt.plot(test_v,sd.get_j_from_v(test_v))
In [65]:
d1.get_j_from_v(-50)
Out[65]:
In [49]:
sd.get_single_j_from_v(2.0)
Out[49]:
In [50]:
d1.j01
Out[50]:
In [51]:
m=1/(sc.k*300/sc.e)
print(m)
In [52]:
jj=-319.8
def eq1(volt):
return -320+d1.j01*np.exp(m*volt)-jj
def eq1_p(volt):
return d1.j01*m*np.exp(m*volt)
def eq_set(volt):
out=[]
out.append(eq1(volt[0]))
out.append(eq1(volt[1]))
return out
def eq_set_p(volt):
out=[]
out.append(d1.j01*m*np.exp(m*volt))
out.append(d1.j01*m*np.exp(m*volt))
return out
def test_eqset(x):
out=[]
out.append(2*x[0]+x[1]-3)
out.append(x[0]*1-3*x[1]-2)
return out
from scipy.optimize import fsolve
In [53]:
fsolve(eq_set,x0=[0.8,0.8],fprime=eq_set_p)
Out[53]:
In [54]:
fsolve(eq1_p,x0=1.2,fprime=eq1_p)
Out[54]:
In [55]:
newton(eq1,x0=1.2,fprime=eq1_p)
Out[55]:
In [56]:
fsolve(test_eqset,x0=[0.8,0.8])
Out[56]:
In [57]:
plt.semilogy(np.exp(m*test_v))
Out[57]:
In [58]:
plt.semilogy(d1.j01*np.exp(m*test_v)+d1.jsc)
Out[58]:
In [59]:
d1.j01/1.0*(np.exp(m*test_v)-1)
Out[59]:
In [60]:
from pypvcell.ivsolver import gen_rec_iv_by_rad_eta
In [61]:
gen_rec_iv_by_rad_eta(d1.j01,rad_eta=1.0,n1=1.0,temperature=300,rshunt=np.inf,voltage=test_v)
Out[61]:
In [66]:
gen_rec_iv_by_rad_eta(d1.j01,rad_eta=1.0,n1=1.0,temperature=300,rshunt=np.inf,voltage=-50)
Out[66]:
In [74]:
d1.j01/1.0*(np.exp(m*(-0.1))
In [ ]: